package org.jetnuke.modules.blog;

import java.io.File;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.jforum.util.preferences.ConfigKeys;
import net.jforum.util.preferences.SystemGlobals;

import org.apache.velocity.VelocityContext;
import org.jetnuke.common.ActionForward;
import org.jetnuke.common.IAction;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IModuleInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.util.JetUtil;

public class DeleteResource implements IAction {
	String file;
	public ActionForward exec(HttpServletRequest request,
			HttpServletResponse response, VelocityContext vc, IModuleInfo info,
			String op, IUserInfo ui, IAdminInfo ai) throws Exception {
		
		
		if(ui==null || ui.getID()<2)
			return null;
		
		String dir=SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_STORE_DIR) + "/blog/"+ui.getID()+"/";
		File f=new File(dir,file);
		if(f.exists())
			f.delete();
		
		JetUtil.redirect(vc,response,request.getContextPath()+"/do/blog/resources");
		return null;
	}
	public void setFile(String file) {
		this.file = file;
	}

}
